package com.ruoyi.place.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.place.domain.bo.PlaceElydBo;
import com.ruoyi.place.domain.vo.PlaceElydVo;
import com.ruoyi.place.service.IPlaceElydService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 易滥用毒品场所
 *
 * @author xiaohao
 * @date 2023-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/place/elyd")
public class PlaceElydController extends BaseController {

    private final IPlaceElydService iPlaceElydService;

    /**
     * 查询易滥用毒品场所列表
     */
    @GetMapping("/list")
    public TableDataInfo<PlaceElydVo> list(PlaceElydBo bo, PageQuery pageQuery) {
        return iPlaceElydService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出易滥用毒品场所列表
     */
    @Log(title = "易滥用毒品场所", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PlaceElydBo bo, HttpServletResponse response) {
        List<PlaceElydVo> list = iPlaceElydService.queryList(bo);
        ExcelUtil.exportExcel(list, "易滥用毒品场所", PlaceElydVo.class, response);
    }

    /**
     * 获取易滥用毒品场所详细信息
     *
     * @param elydId 主键
     */
    @GetMapping("/{elydId}")
    public R<PlaceElydVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long elydId) {
        return R.ok(iPlaceElydService.queryById(elydId));
    }

    /**
     * 新增易滥用毒品场所
     */
    @Log(title = "易滥用毒品场所", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PlaceElydBo bo) {
        return toAjax(iPlaceElydService.insertByBo(bo));
    }

    /**
     * 修改易滥用毒品场所
     */
    @Log(title = "易滥用毒品场所", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PlaceElydBo bo) {
        return toAjax(iPlaceElydService.updateByBo(bo));
    }

    /**
     * 删除易滥用毒品场所
     *
     * @param elydIds 主键串
     */
    @Log(title = "易滥用毒品场所", businessType = BusinessType.DELETE)
    @DeleteMapping("/{elydIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] elydIds) {
        return toAjax(iPlaceElydService.deleteWithValidByIds(Arrays.asList(elydIds), true));
    }
}
